A virtual machine (VM) has advantages in convenience, safety, security, and portability. However, initializing and loading an application in a VM typically incurs a significant cost, which multiplies when the application and its VM are launched multiple times. Isolating independent tasks in separate operating system processes avoids negative impacts on performance, safety, and security between the tasks. However, spawning separate processes incurs significant initialization costs and increased memory usage, especially for an application running on a VM.
Threads, which are also referred to as light-weight processes, are an approach to reduce initialization costs and memory usage by sharing the execution context of a host process. However, using threads provides little isolation, and therefore provides few benefits in safety and security. Moreover, the resources of a finished task belong to the host process and must be reclaimed individually.
Another approach is to initialize a pool of processes, and to assign each task to a process in the pool. Using a process pool provides a level of isolation similar to spawning tasks on demand, but allows earlier tasks to negatively affect later tasks, for example, when a process incurs a resource leak. Moreover, multiple processes incur increased memory usage, and generally require the reclamation of individual resources.
Multi-tenant extensions to programming languages (e.g., Java) allow a class loaded once by the VM to be used by multiple independent tenants by replicating the mutable static state (and only the static state, not immutable parts, like the code). However, every tenant still performs the same static class initialization steps.
A more radical approach for applications with strict goals of both isolation and low initialization costs is to avoid the use of a VM and instead rely on unmanaged languages without runtime systems that incur less setup cost for spawning processes. However, using unmanaged languages without runtime systems reduces maintainability, portability, safety, security and convenience.